<nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="#">CODE-SKY</a>
    </div>
    <div id="navbar" class="navbar-collapse collapse">
      <ul class="nav navbar-nav">
        <li class="active"><a href="/">首页</a></li>
        <li><a href="/about">关于</a></li>
        <li><a href="/works">作品</a></li>
        <li><a href="//admin.code-sky.cn/login">Admin管理</a></li>
      </ul>
    </div>
  </div>
</nav>
<script>
  (function() {
    var lis = document.querySelectorAll('.navbar-nav li');
    var pathname = location.pathname;
    if (pathname !== '/') {
      lis.forEach((item, index) => {
        var curPath = item.querySelector('a').getAttribute('href');
        if (pathname.indexOf(curPath) > -1 && curPath !== '/') {
          item.classList.add('active');
        } else  {
          item.classList.remove("active");
        }
      })
    }
  })()
</script>
